//
//  DYRechargeMoneySetView.m
//  kafuMerchant
//
//  Created by 帝云科技 on 2018/9/18.
//  Copyright © 2018年 帝云科技. All rights reserved.
//

#import "DYRechargeMoneySetView.h"


@interface DYRechargeMoneySetView ()

@property (nonatomic,strong)UILabel *discountLabel;
@property (nonatomic,strong)UIButton *discountButton1;
@property (nonatomic,strong)UIButton *discountButton2;
@property (nonatomic,strong)UIButton *discountButton3;
@property (nonatomic,strong)DYRechargeMoneySetChildView *rechargeView;
@property (nonatomic,strong)DYRechargeMoneySetChildView *giveView;

@property (nonatomic,strong)UILabel *tipLabel;
@property (nonatomic,strong)UIButton *setButton;

@end

@implementation DYRechargeMoneySetView

-(instancetype)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self) {
        [self initView];
    }
    return self;
}
-(void)initView
{
    self.backgroundColor=WhiteColor;

    self.rechargeView = ({
        DYRechargeMoneySetChildView *view=[[DYRechargeMoneySetChildView alloc]init];
        view;
    });

    self.giveView = ({
        DYRechargeMoneySetChildView *view=[[DYRechargeMoneySetChildView alloc]init];
        view;
    });
    
    self.discountLabel = ({
        UILabel *label=[Utils labelWithTitle:@"折扣比例" titleFontSize:12 textColor:[UIColor xhq_content] backgroundColor:WhiteColor alignment:0]
        ;
        label;
    });
    
    self.discountButton1= ({
        UIButton *button=[Utils createBtnWithType:UIButtonTypeCustom backgroundColor:WhiteColor action:@selector(buttonClick:) target:self title:@"暂无折扣" image:nil font:13 textColor:[UIColor xhq_base]];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        [button xhq_cornerRadius:BILIHEIGHT(13)];
        [button xhq_borderColor:[UIColor xhq_base] borderWidth:BILIWIDTH(0.7)];
        button.selected=YES;
        button.backgroundColor=[UIColor xhq_base];
        button;
    });
    self.discountButton2= ({
        UIButton *button=[Utils createBtnWithType:UIButtonTypeCustom backgroundColor:WhiteColor action:@selector(buttonClick:) target:self title:@"充值折扣" image:nil font:13 textColor:[UIColor xhq_base]];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        [button xhq_cornerRadius:BILIHEIGHT(13)];
        [button xhq_borderColor:[UIColor xhq_base] borderWidth:BILIWIDTH(0.7)];
        button;
    });
    self.discountButton3= ({
        UIButton *button=[Utils createBtnWithType:UIButtonTypeCustom backgroundColor:WhiteColor action:@selector(buttonClick:) target:self title:@"充值赠送" image:nil font:13 textColor:[UIColor xhq_base]];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        [button xhq_cornerRadius:BILIHEIGHT(13)];
        [button xhq_borderColor:[UIColor xhq_base] borderWidth:BILIWIDTH(0.7)];
        button;
    });
  
    self.tipLabel = ({
        UILabel *label=[Utils labelWithTitle:@"提示：该设置为客户充值时选择的充值金额选项及对应折扣，请正确设置金额。" titleFontSize:12 textColor:[UIColor xhq_content] backgroundColor:WhiteColor alignment:0];
        label.numberOfLines=0;
        label;
    });
    
    self.setButton = ({
        UIButton *button=[Utils createBtnWithType:UIButtonTypeCustom backgroundColor:[UIColor xhq_base] action:@selector(buttonClick:) target:self title:@"确认设置" image:@"icon_login" font:17 textColor:[UIColor whiteColor]];
        [button xhq_cornerRadius:BILIHEIGHT(19)];
        button;
    });
    
    [self addSubview:self.rechargeView];
    [self addSubview:self.discountLabel];
    [self addSubview:self.discountButton1];
    [self addSubview:self.discountButton2];
    [self addSubview:self.discountButton3];
    [self addSubview:self.tipLabel];
    [self addSubview:self.giveView];
    [self addSubview:self.setButton];
    
    
    [self.rechargeView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(BILIHEIGHT(20));
        make.left.equalTo(BILIWIDTH(10));
        make.right.equalTo(BILIWIDTH(-10));
        make.height.equalTo(BILIHEIGHT(50));
    }];
    
    [self.discountLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.rechargeView);
        make.top.equalTo(self.rechargeView.bottom).offset(BILIHEIGHT(10));
    }];
    
    [self.discountButton1 makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.rechargeView);
        make.top.equalTo(self.discountLabel.bottom).offset(BILIHEIGHT(6));
        make.size.equalTo(CGSizeMake(BILIWIDTH(88), BILIHEIGHT(26)));
    }];
    
    [self.discountButton2 makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.discountButton1.right).offset(BILIWIDTH(15));
        make.centerY.equalTo(self.discountButton1);
        make.size.equalTo(self.discountButton1);
    }];
    
    [self.discountButton3 makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.discountButton2.right).offset(BILIWIDTH(15));
        make.centerY.equalTo(self.discountButton1);
        make.size.equalTo(self.discountButton1);
    }];
    
    [self.giveView makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.rechargeView);
        make.top.equalTo(self.discountButton2.bottom).offset(BILIHEIGHT(15));
        make.height.equalTo(0);
    }];
    
    [self.tipLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.rechargeView);
        make.top.equalTo(self.giveView.bottom).offset(BILIHEIGHT(10));
    }];
    
    
    [self.setButton makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(BILIWIDTH(-15));
        make.top.equalTo(self.tipLabel.bottom).offset(BILIHEIGHT(150));
        make.size.equalTo(CGSizeMake(BILIWIDTH(132), BILIHEIGHT(38)));
    }];

    [self.setButton placeImageTitlePosition:ZYButtonImagePositionRight space:BILIWIDTH(10)];
    self.giveView.hidden=YES;
    
    [self.tipLabel xhq_lineSpace:BILIHEIGHT(3)];
    
}
-(void)buttonClick:(UIButton *)button
{
    if (button==self.setButton) {
        
    }else{
        
        self.discountButton1.selected=NO;
        self.discountButton2.selected=NO;
        self.discountButton3.selected=NO;
        self.discountButton1.backgroundColor=WhiteColor;
        self.discountButton2.backgroundColor=WhiteColor;
        self.discountButton3.backgroundColor=WhiteColor;
        button.selected=!button.selected;
        if (button.selected) {
            button.backgroundColor=[UIColor xhq_base];
        }
        
        if (button!=self.discountButton1) {
            [self.giveView updateConstraints:^(MASConstraintMaker *make) {
                make.height.equalTo(BILIHEIGHT(50));
            }];
            self.giveView.hidden=NO;
            
            if (button==self.discountButton2) {
                self.giveView.titleLabel.text=@"折扣比例( % )";
                self.giveView.moneyTextField.placeholder=@"请设置折扣比例";
            }else{
                self.giveView.titleLabel.text=@"赠送金额( ¥ )";
                self.giveView.moneyTextField.placeholder=@"请设置赠送金额";
            }
        }else{
            [self.giveView updateConstraints:^(MASConstraintMaker *make) {
                make.height.equalTo(BILIHEIGHT(0));
            }];
             self.giveView.hidden=YES;
        }
        
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end




@interface DYRechargeMoneySetChildView ()


@end

@implementation DYRechargeMoneySetChildView

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self=[super initWithFrame:frame]) {
        [self initView];
    }
    return self;
}
-(void)initView
{
    self.titleLabel = ({
        UILabel *label=[Utils labelWithTitleFontSize:12 textColor:[UIColor xhq_content] alignment:0];
        label.text=@"充值金额( ¥ )";
        label;
    });
    
    self.moneyTextField = ({
        UITextField *text=[[UITextField alloc]init];
        [text setNumbersKeyboard];
        text.font=kFont(14);
        text.placeholder=@"请设置充值金额";
        [text setValue:[UIColor xhq_assist] forKeyPath:@"_placeholderLabel.textColor"];
        text;
    });

    
    self.line= ({
        UILabel *line=[UILabel xhq_lineLabel];
        line;
    });
    
    [self addSubview:self.titleLabel];
    [self addSubview:self.moneyTextField];
    [self addSubview:self.line];
    
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(BILIWIDTH(0));
        make.top.equalTo(BILIHEIGHT(5));
    }];
    
    [self.moneyTextField makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(BILIWIDTH(0));
        make.right.equalTo(BILIWIDTH(0));
        make.height.equalTo(BILIHEIGHT(30));
        make.bottom.equalTo(BILIWIDTH(-0.7));
    }];
    
    [self.line makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(BILIWIDTH(0));
        make.right.equalTo(BILIWIDTH(0));
        make.bottom.equalTo(0);
        make.height.equalTo(BILIWIDTH(0.7));
    }];
    
    
//    self.moneyTextField.backgroundColor=[UIColor xhq_base];
    
    
}
@end
